package com.example.demo.线程;

import java.util.List;

/**
 * @description:
 * @projectName:demo
 * @see:线程
 * @author:袁成龙
 * @createTime:2020/10/6 19:14
 * @version:1.0
 */
public class TestRunnd2 implements Runnable{

    private List<Integer> list;

    public TestRunnd2(List<Integer> list) {
        this.list = list;
    }

    //加在static 是类对象,记在普通方法上是实例对象,当一个新的实例对象进来的时候void是没用的


    public synchronized  void test01(List<Integer> list){
        /*for (int i = 0; i < 1000; i++) {
            list.add(i);
        }*/
        synchronized ("11111"){
            for (int i = 0; i < 1000; i++) {
                list.add(i);
            }
        }
    }



    public static synchronized  void test02(List<Integer> list){
        for (int i = 0; i < 1000; i++) {
            list.add(i);
        }
        System.out.println("静态=================");
    }

    @Override
    public void run() {
        test01(list);
    }
}